package com.ayoka.ui.course.detail;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.ayoka.R;
import com.ayoka.base.BaseActivity;
import com.ayoka.bean.CourseBean;
import com.ayoka.databinding.ActivityCourseConcludeBinding;
import com.ayoka.mvp.CourseMVP.CoursePresenter;
import com.ayoka.utils.WeChatManager;
import com.ayoka.utils.WeChatShareManager;
import com.ayoka.widget.ShareDialog;
import com.jcp.baselibrary.model.ToolBarOptions;
import com.jcp.baselibrary.utils.DateUtil;
import com.jcp.baselibrary.utils.ScreenShotUtils;


/**
 * @author jcp
 * @ClassName: TopicListActivity
 * @Description:
 * @date 2018-12-28 下午4:21:18
 */
public class CourseConcludeActivity extends BaseActivity<ActivityCourseConcludeBinding, CoursePresenter> {

    public static void start(Activity activity, long courseId) {
        Intent intent = new Intent(activity, CourseConcludeActivity.class);
        intent.putExtra("CourseId", courseId);
        activity.startActivity(intent);
    }

    private long courseId;
    private CourseBean courseBean;

    private WeChatShareManager mShareManager;

    @Override
    protected void configIntentValue() {
        courseId = getIntent().getLongExtra("CourseId", 0);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_course_conclude;
    }

    @Override
    protected void initViews() {
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        setCustomToolBar(mDataBinding.customToolbar.toolbar, new ToolBarOptions());

        mShareManager = WeChatShareManager.getInstance(this);
        mPresenter.getCourseDetailData(courseId);
    }

    @Override
    protected CoursePresenter getPresenter() {
        return null;
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.course_conclude_menu, menu);//加载menu文件到布局
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        if (item.getItemId() == R.id.action_share) {
            showShareDialog(getSupportFragmentManager());
        }
        return true;
    }

    public void showShareDialog(FragmentManager fragmentManager) {
        ShareDialog dialog = new ShareDialog.Builder()
                .setGravity(Gravity.BOTTOM)
                .setAnimation(R.style.SlideBottomAnimation)
                .setSize(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .build();
        dialog.setShareSelectedListener(new ShareDialog.OnShareSelectedListener() {
            @Override
            public void onShareSelected() {
                share();
            }
        });
        dialog.show(fragmentManager, "CustomConfirmDialog");
    }

    private void share() {
        if (!WeChatManager.getInstance().isWXAppInstalled()) {
            return;
        }
        Bitmap screenShotBitmap = ScreenShotUtils.shotView(mDataBinding.rlContainer);
        WeChatShareManager.ShareContentMiniProgram miniProgram = (WeChatShareManager.ShareContentMiniProgram) mShareManager.getShareContenMiniProgram("阿尤卡亲子", "来自「」社群的成长报告" + DateUtil.getCurrentDate("(MM月dd日)") , "http://www.ayoka.com", "gh_7fcb8a63dc30", "/pages/Group/DailyPunchReport?group_id=", screenShotBitmap);
        mShareManager.shareByWebchat(miniProgram, WeChatShareManager.WECHAT_SHARE_TYPE_TALK);
    }
}
